from manim import *
class CustomCurve(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [-15, 15, 0],
            [-16,14,0],
            [-17,4,0],
            [-23, 0, 0],
            [-17, -4, 0],
            [-16,-14,0],
            [-15,-15,0],
        ]
        self.set_points_smoothly(points)
class CustomCurve1(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [5, 12, 0],
            [0,8,0],
            [5,7,0],
        ]
        self.set_points_smoothly(points)
class CustomCurve2(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [5, 3.5, 0],
            [0,0,0],
            [5,-1,0],
        ]
        self.set_points_smoothly(points)
class CustomCurve3(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [5, -6, 0],
            [0,-8,0],
            [5,-11,0],
        ]
        self.set_points_smoothly(points)
class CustomCurve4(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [5, -14, 0],
            [0,-15,0],
            [5,-19,0],
        ]
        self.set_points_smoothly(points)

class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
         #镜头跟进效果
        self.camera.frame.save_state()
         #中心主题+框框标记
        text1 = Tex(r"\text{二重积分}",color=PINK
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=19,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-35, 0, 0])
        self.play(Create(rectangle),Create(text1),FadeIn(dot1),FadeIn(dot2),FadeIn(dot3))
       
        curve = CustomCurve(color=RED, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve))
        self.wait(0.2)

        text2 = Tex(r"\text{定义求极限}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-8,15,0])
        text3 = Tex(r"\text{对称性化简}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-8,8,0])
        text4 = Tex(r"\text{计算方法}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-8,0,0])
        text5 = Tex(r"\text{运算小技巧}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-8,-8,0])
        text6 = Tex(r"\text{补充}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-8,-15,0])
        self.play(Create(text2),Create(text3),Create(text4),Create(text5),Create(text6))

        curve1 = CustomCurve1(color=RED, stroke_width=20)
        
        

        text7 = Tex(r"\text{奇偶性}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,12,0])
        text8 = Tex(r"\text{轮换性}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,7,0])

    

        curve2 = CustomCurve2(color=RED, stroke_width=20)
        

        text9 = Tex(r"\text{直角坐标系}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([12,3.5,0])
        text90 = Tex(r"\text{(先x后y,先y后x)}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text9,RIGHT,buff=1)
        text10 = Tex(r"\text{极坐标系}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,-1,0])

   


        curve3 = CustomCurve3(color=RED, stroke_width=20)
        
      

        text11 = Tex(r"\text{广义奇偶性,割补法}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([18,-6,0])
        text12 = Tex(r"\text{极点平移,椭圆化圆}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([18,-11,0])

     

        curve4 = CustomCurve4(color=RED, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve4),Create(curve3),Create(curve2),Create(curve1))
        self.wait(0.2)

        text13 = Tex(r"\text{参数方程D,反常二重积分}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([23,-14,0])
        text14 = Tex(r"\text{分段函数}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([11,-19,0])

        self.play(Create(text7),Create(text8),Create(text9),Create(text90),Create(text10),Create(text11),Create(text12)
                  ,Create(text13),Create(text14))
    
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=90,height=50
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle2.move_to([0,0,0])
        self.play(Create(rectangle2))
        text12 = Tex(r"\text{解题思路结构化}" ,color=PURE_RED  
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle2,UP,buff=1)
        self.play(Create(text12))
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=PURE_GREEN,stroke_width=20)
        rectangle1.move_to([-8,-8,0])
        self.play(Create(rectangle1),self.camera.frame.animate.scale(0.6).move_to([-8,-8,0]))

    


        
        self.wait()